package logic

import (
	"context"
	"good_srv/models"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MerchantListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMerchantListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MerchantListLogic {
	return &MerchantListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商家列表
func (l *MerchantListLogic) MerchantList(in *good.MerchantListRequest) (*good.MerchantListResponse, error) {
	// todo: add your logic here and delete this line
	var merchants models.Merchant
	m, _ := merchants.MerchantList(in.Sort, in.TypeId, float64(in.Sprice), float64(in.Price), in.Active)
	var merchantlists []*good.MerchantList
	for _, i2 := range m {
		list := &good.MerchantList{
			Name:       i2.Name,
			Price:      i2.Price,
			Soles:      i2.Soles,
			Score:      i2.Score,
			Ride:       i2.Ride,
			TypeId:     i2.TypeId,
			Sprice:     i2.Sprice,
			Active:     i2.Active,
			Image:      i2.Image,
			StatusName: i2.StatusName,
		}
		merchantlists = append(merchantlists, list)
	}
	return &good.MerchantListResponse{
		List: merchantlists,
	}, nil
}
